<?php
/**
 * +----------------------------------------------------------------------
 * | summer framework
 * +----------------------------------------------------------------------
 * | Copyright (c) 2020 https://github.com/suframe/think-admin All rights reserved.
 * +----------------------------------------------------------------------
 * | Author: summer <806115620@qq.com>  2020/3/30 14:30
 * +----------------------------------------------------------------------
 */
declare (strict_types = 1);

namespace app\mall\model\traits;

use app\mall\model\MallGoods;
use think\Model;
use think\model\relation\BelongsTo;

/**
 * 获取商品
 * trait GoodsTrait
 * @package app\mall\model\traits
 * @mixin Model
 * @property integer $goods_id
 * @property array $goods_info
 * @property MallGoods $goods
 */
trait GoodsTrait
{

    /**
     * 获取商品
     * @return BelongsTo
     */
    public function goods(): BelongsTo
    {
        return $this->belongsTo(
            MallGoods::class,
            'goods_id',
            'id')
            ->cache('modelBelongsGoods' .$this->goods_id, 2);
    }

    public function goodsBind()
    {
        return $this->goods()->bind(['title', 'image']);
    }

}